'''
Created on 13.10.2011

@author: hkh
'''
from CashFlowUtils.CashFlowSchedule import *
from TimeUtils.daterolling import *
from TimeUtils.daycount import *
from TimeUtils.utils import *
from datetime import date

firstInterestDate      = date(2004,06,15)
maturityDate           = date(2044,06,15)
#firstInterestDate      = date(2008,8,15)
#maturityDate           = date(2024,02,15)
frequencyYear          = 2
'''
cf = []
cashFlowDate = maturityDate
cf.append(CashFlow(maturityDate, 0))
i = 1
while cashFlowDate > firstInterestDate:
    cashFlowDate = submonth(maturityDate, i*12/frequencyYear)
    if cashFlowDate < firstInterestDate:
        break
    daysPeriod = cashFlowDate.toordinal() - cf[i-1].cfdate.toordinal()
    cashFlow = CashFlow(cashFlowDate, daysPeriod)
    cf.append(cashFlow)
    i += 1
cf.reverse()
'''

'''
Backward date generation
'''
cf = []
cashFlowDate    = maturityDate
newcashFlowDate = maturityDate
i = 1
while newcashFlowDate >= firstInterestDate:
    #print i*12/frequencyYear
    newcashFlowDate = submonth(maturityDate, i*12/frequencyYear)
    daysPeriod = cashFlowDate.toordinal() - newcashFlowDate.toordinal()
    cashFlow = CashFlow(cashFlowDate, daysPeriod)
    cf.append(cashFlow)
    cashFlowDate = newcashFlowDate
    i += 1
cf.reverse()

    
for item in cf:
    print item.cfdate, item.daysPeriod
'''
for i in range(1,n*self.frequencyYear+1):
    'We need to cast exception if cashflow day doesnt exist for given month.'
    cashFlowDate = addmonth(self.firstInterestDate, i*12/self.frequencyYear)
    if self.dateRollingConvention == DateRollingConvention.following:
        cashFlowDate = self.__following(cashFlowDate)
    elif self.dateRollingConvention == DateRollingConvention.modifiedfollowing:
        cashFlowDate = self.__modifiedFollowing(cashFlowDate)
    elif self.dateRollingConvention == DateRollingConvention.preceding:
        cashFlowDate = self.__preceding(cashFlowDate)
    elif self.dateRollingConvention == DateRollingConvention.modifiedpreceding:
        cashFlowDate = self.__modifiedPreceding(cashFlowDate)
    else:
        pass
    daysPeriod = cashFlowDate.toordinal() - cf[i-1].cfdate.toordinal()
    #while cashFlowDate > self.firstInterestDate:
                
    cashFlow = CashFlow(cashFlowDate, daysPeriod)
    cf.append(cashFlow)
return cf
'''